<?php #title=Страницы;

$view->title='Редактор страниц';
$parents=!empty($_GET['par'])?urldecode($_GET['par']):'';
$view->gText.='<div id="pager_crumbs">';
$pre_url='';
$last_catalog=false;
if(!empty($parents))
{
	$ids=implode(',',getIdsArr($parents));
	$conn->query("select title,id,url,if(templ='product_catalog_last',1,0) as last_catalog from pages where id in($ids) order by parents");
	$parens='';
	$end=$conn->rowCount()-1;
	$i=0;
	$links=array('/admin?p=_pages#pager_crumbs'=>'Корень');
	while($row=$conn->fetch())
	{
		if($i++<$end)
		{
			$parens.="#{$row->id}#";
			$links['/admin?p=_pages&par='.urlencode($parens).'#pager_crumbs']=$row->title;
		}
		else
		{
			$links[]=$row->title;
			if($row->last_catalog)
				$last_catalog=true;
		}
		$pre_url.="/{$row->url}";
	}
	$view->gText.=$load->block('crumbs',array('links'=>$links));
}
$parans_url=urlencode($parents);
$view->gText.=$load->block('buttons',array('style'=>'add','link'=>'/admin?p=_pages&par='.$parans_url.'&edit_id=new&add_page_to='.$parans_url.'','text'=>'Добавить страницу в этот раздел'))
	.'</div>';
/*Список шаблонов*/
$template_arr=$cache->get('admin/site_templs','get_comment_params','templ');
$template_arr=(isset($template_arr['templs']))?$template_arr['templs']:array();
if(!empty($_GET['edit_id']))
{
	//if(!empty($_GET['templ']) && $_GET['templ']=='product')
	//	successRedirect(array('url'=>'?p=_store_catalog&page_id='.$_GET['edit_id']));
	$view->gText.='<form action=""  method="post">'.$load->block('page_editor',array(
		'page_id'=>$_GET['edit_id'],
		'parents'=>(isset($_GET['add_page_to'])?$_GET['add_page_to']:false),
	)).'</form>';
}
	
	
$view->gText.=$load->block('table_editor',array(
	'control_name'=>'Быстрое редактирование',
	'can_edit'=>true,
	'dev'=>true,
	'select'=>array('from'=>'pages p,users u', 'where'=>"p.parents='$parents' and u.id=p.editor_id"),
	'delete'=>array('delete from pages where id in(#sys_ids#)','delete from pages_attachments where page_id in(#sys_ids#)'),
	'insert'=>array('page_id'=>"insert into pages (title) values('#title#')","insert into pages_attachments (page_id,params,type) values('#page_id#','#params#','#type#')"),
	'update'=>"update pages set title='#title#',url='#getGoodUrl|url#', zin=#zin# WHERE id = #sys_id#",
	'fields'=>array(
		'id'=>array('query_name'=>'p.id','sys_id'=>true,'title'=>'ID','to_edit'=>false),
		'title'=>array('query_name'=>'p.title','title'=>'Заголовок','link'=>'<a href="/admin?p=_pages&par='.urlencode($parents).'%23#id#%23#pager_crumbs">#title#</a>'),
		/* 'h1'=>array('query_name'=>'p.h1','title'=>'H1'), */
		'url'=>array('query_name'=>'p.url','title'=>'Ссылка'),
		'editor_id'=>array('query_name'=>'concat(date_format(p.date_last_edit,\'<b>%d.%m.%Y</b> %T\'),\' <b>\',u.name,\'</b>\')','title'=>'Редакция от','to_edit'=>'false'),
		'templ'=>array('query_name'=>'p.templ','title'=>'Шаблон','type'=>'select','values'=>$template_arr,'to_edit'=>false),
		'zin'=>array('query_name'=>'p.zin','title'=>'Сорт.'),
		array('link'=>'<a href="?p=_pages&par='.urlencode($parents).'%23#id#%23&edit_id=#id#&templ=#templ##page_edit">подробнее</a>','to_edit'=>false),
		array('link'=>'<a href="'.$pre_url.'/#url#">на страницу</a>','to_edit'=>false),
		),
	'link_replaces'=>array('parents')
))
;
